*** One-Child Policy, Marriage Distortion, and Welfare Loss ***
*** by Wei Huang, Yinghao Pan and Yi Zhou ***

clear all 
set more off
set scheme s1color
cap log close 
graph set window fontface "Times New Roman"

set niceness 10
gl MAIN = "F:\Dropbox"

gl path1 = "$MAIN/Census"
gl path2 = "$MAIN/Marriage/Working_data"
gl path3 = "$MAIN/Marriage/Restat/dataverse_files/Results" 
gl path4 = "$MAIN/Marriage/Restat/dataverse_files/Graphics" 

gl CONTROL = " year_birth sex#age urban_hk prov_hk##c.(year_birth ) "
gl CONTROL_han = " han#year_birth  han#urban_hk han#sex#age han#prov_hk##c.(year_birth ) "

gl CONTROL_policy = " mino_policy#year_birth  mino_policy#urban_hk mino_policy#sex#age mino_policy#prov_hk##c.(year_birth ) "


use "$path2/unmarried", clear
keep if relation == 0 | relation == 1 | relation == 2 | relation == 6 

merge 1:1 wave area hhid name relation using "$path2/min_marr_policy", keepusing(marry_1 marry_2 marry_3)


drop if mi(hktype)
replace urban = hktype == 1 
su age 

gen han = 1- minority 

replace unmarried = unmarried * 100 
gen unmarr_25 = marr_age > 25 if !mi(marr_age)
replace unmarr_25 = 1 if unmarried == 100 
replace unmarr_25 = unmarr_25 *100 

gen urban_hk = hktype == 2 


gen marry_9 = unmarried == 0 & (mi(marry_1) & mi(marry_2) & mi( marry_3))

recode marry_1 marry_2 marry_3 (. = 0) 

gen HH = marry_1 * 100 
gen HM = marry_2 * 100 
gen MM = marry_3 * 100 
gen Other = marry_9 * 100 
gen HOMO = HH + MM
su HOMO

keep if age <= 55 
keep if age > 25
keep if year_birth <= 1980 
keep if Other == 0 

egen n_birth = rowtotal(numbirm numbirf)


cap erase "$path3/marriage_f_test.xls"
cap erase "$path3/marriage_f_test.txt"

*** Column 1 of Table 1 ***
foreach policy in "1" "mino_policy == 1"  "mino_policy == 0"  {
preserve 
keep if `policy'  


reghdfe unmarried c.fine_16_25##han  [aw = aw], a($CONTROL_han)   cluster(prov_hk)
test 1.han#c.fine_16_25=0.han#c.fine_16_25
local f1 = string(r(F),"%9.3f")
local p1 = string(r(p),"%9.3f")
outreg2 using "$path3/marriage_f_test.xls", append dec(3)  addtext("F-statistics", "`f1'","P-values","[`p1']")   ctitle(fine_`age'& prov_hk)


restore


}



*** Columns 3-4 of Table 1 ***



foreach eth in  "han" "han == 0"{
preserve 
keep if  `eth'&unmarried == 0


reghdfe HM c.fine_16_25##mino_policy [aw = aw], a($CONTROL_policy)  cluster(prov_hk)
test 1.mino_policy#c.fine_16_25=0.mino_policy#c.fine_16_25
local f1 = string(r(F),"%9.3f")
local p1 = string(r(p),"%9.3f")
outreg2 using "$path3/marriage_f_test.xls", append dec(3)  addtext("F-statistics", "`f1'","P-values","[`p1']")   ctitle(fine_`age'& prov_hk)
restore


}



keep if age <= 45
keep if sex == 2 


cap erase "$path3/birth_f_test.xls"
cap erase "$path3/birth_f_test.txt"

*** Table 2 ***

foreach policy in "1" "mino_policy == 1"  "mino_policy == 0"  {
preserve 
keep if `policy'  


reghdfe n_birth c.fine_16_25##han  [aw = aw], a($CONTROL_han)   cluster(prov_hk)
test 1.han#c.fine_16_25=0.han#c.fine_16_25
local f1 = string(r(F),"%9.3f")
local p1 = string(r(p),"%9.3f")
outreg2 using "$path3/birth_f_test.xls", append dec(3)  addtext("F-statistics", "`f1'","P-values","[`p1']")   ctitle(fine_16_25& prov_hk)


restore


}


use "$path2/min_marr_policy", clear 
ren pid pid_t 
ren spouse_pid pid 
ren educ educ_t
set more off 
fmerge 1:1 pid using "$path2/min_marr_policy", keepusing(educ) keep(3)
ren educ educ_sp
ren educ_t educ 
drop if mi(hktype)

replace urban = hktype == 1 
gen urban_hk = hktype == 2 

gen han = 1- minority 

keep if age <= 55 
keep if age > 25
keep if year_birth <= 1980 

egen clsid = group(prov_hk year_birth)
egen fine_16_25 = rowmean(fine_16-fine_25)

gen educ_sp_h = educ_sp >= 4 

replace educ_sp_h = educ_sp_h *100
cap erase "$path3/match_f_test.xls"
cap erase "$path3/match_f_test.txt"
preserve
keep if  ( (marry_1 == 1 & han == 1 ) | (marry_2 ==1 & minority == 1) )
gen treat = marry_2 ==1 & minority == 1

*** Column 3 of Table 3 ***
reghdfe educ_sp_h c.fine_16_25##han [aw = aw]  if   mino_policy == 1, a(han#educ han#year_birth  han#urban_hk han#sex#age han#prov_hk##c.(year_birth ) )   cluster(prov_hk)
test 1.han#c.fine_16_25=0.han#c.fine_16_25
local f1 = string(r(F),"%9.3f")
local p1 = string(r(p),"%9.3f")
outreg2 using "$path3/match_f_test.xls", append  ctit(educ_sp & mino_policy == 1 ) dec(3) addtext("F-statistics", "`f1'","P-values","[`p1']") 


restore 

keep if marry_2 == 1

*** Column 2 of Table 3 ***


reghdfe educ_sp_h c.fine_16_25##han [aw = aw]  if  mino_policy == 1, a(han#educ han#year_birth  han#urban_hk han#sex#age han#prov_hk##c.(year_birth ) )   cluster(prov_hk)
test 1.han#c.fine_16_25=0.han#c.fine_16_25
local f1 = string(r(F),"%9.3f")
local p1 = string(r(p),"%9.3f")
outreg2 using "$path3/match_f_test.xls", append  ctit(educ_sp & mino_policy == 1)  dec(3) bracket addtext("F-statistics", "`f1'","P-values","[`p1']") 





*** Column 1 of Table 3 ***

reghdfe educ_sp_h c.fine_16_25##mino_policy [aw = aw]  if  han ==0 , a(mino_policy#educ mino_policy#year_birth  mino_policy#urban_hk mino_policy#sex#age mino_policy#prov_hk##c.(year_birth ) )   cluster(prov_hk)
test 1.mino_policy#c.fine_16_25=0.mino_policy#c.fine_16_25
local f1 = string(r(F),"%9.3f")
local p1 = string(r(p),"%9.3f")
outreg2 using "$path3/match_f_test.xls", append  ctit(educ_sp &  `eth')  dec(3) bracket addtext("F-statistics", "`f1'","P-values","[`p1']") 
